package com.sinosoft.flow.config;

import com.sinosoft.flow.intercepter.TokenIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: njz
 * @Description:
 * @Date: create in 2022/1/14 17:55
 */
@Configuration
public class TokenIntecepterConfig implements WebMvcConfigurer {

    @Autowired
    private TokenIntercepter tokenIntercepter;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(tokenIntercepter);
        registration.addPathPatterns("/api/**");                      //所有路径都被拦截
        registration.excludePathPatterns(                         //添加不拦截路径
                "/api/user/login",            //登录
                "/**/*.html",            //html静态资源
                "/**/*.js",              //js静态资源
                "/**/*.css",             //css静态资源
                "/**/*.woff",
                "/**/*.ttf"
        );
    }
}
